package com.huifaapp.mall.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.huifaapp.mall.R;
import com.huifaapp.mall.bean.WaitpayBean;

import java.util.List;

/**
 * Created by mac on 2017/12/11.
 */

public class WaitPayAdapter extends RecyclerView.Adapter {


    private Context context;
    private MyViewHolder myViewHolder;
    //private List<PendingPayBean.DataBean>goods;
    private WaitpayBean.DataBean goods;
    private List<WaitpayBean.DataBean.OrderItemBean> orderItemBeanList;

    public WaitPayAdapter(Context context, WaitpayBean.DataBean goods, List<WaitpayBean.DataBean.OrderItemBean> orderItemBeanList) {
        this.context = context;
        this.goods = goods;
        this.orderItemBeanList = orderItemBeanList;
    }

    //    public WaitPayAdapter(Context context, List<PendingPayBean.DataBean> goods) {
//        this.context = context;
//        this.goods = goods;
//    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view =  LayoutInflater.from(context).inflate(R.layout.waitpayl_item,null);
        myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

//        Glide.with(context).load(goods.get(position).getGoodsImg()).into(myViewHolder.im_shop);
//        myViewHolder.shop_name.setText(goods.get(position).getGoodsName());
//        myViewHolder.shop_color.setText(goods.get(position).getGoodsColor());

        WaitpayBean.DataBean.OrderItemBean orderItemBean = orderItemBeanList.get(position);
        Glide.with(context).load(orderItemBean.getGoodsImg()).into(myViewHolder.im_shop);
        myViewHolder.shop_name.setText(orderItemBean.getGoodsName());
        WaitpayBean.DataBean.OrderItemBean.ParamBean param = orderItemBean.getParam();
        String color = param.get颜色() == null ? "无" : param.get颜色();   //三元运算符   判断param.getColor()是否为null  如果是null则取 : 前面的值，否则后面的值
        String brand = param.get尺寸() == null ? "**" : param.get尺寸();   //同上
        myViewHolder.shop_color.setText(color + "；");   //商品的颜色
        myViewHolder.shop_size.setText(brand);
        myViewHolder.shop_xj.setText("¥"+orderItemBean.getPrice()+"");
        myViewHolder.shop_yj.setText("¥"+orderItemBean.getOrginPrice()+"");
        myViewHolder.shop_num.setText("x"+orderItemBean.getCount()+"");
    }

    @Override
    public int getItemCount() {
        return orderItemBeanList.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView im_shop;
        TextView shop_name;
        TextView shop_color;
        TextView shop_size;
        TextView shop_xj;
        TextView shop_yj;
        TextView shop_num;
        public MyViewHolder(View itemView) {
            super(itemView);
            im_shop = (ImageView) itemView.findViewById(R.id.waitpay_shopim);
            shop_name = (TextView) itemView.findViewById(R.id.waitpay_shopname);
            shop_color = (TextView) itemView.findViewById(R.id.waitpay_shopcolor);
            shop_size = (TextView) itemView.findViewById(R.id.waitpay_shopsize);
            shop_xj = (TextView) itemView.findViewById(R.id.waitpay_xj);
            shop_yj = (TextView) itemView.findViewById(R.id.waitpay_yj);
            shop_num = (TextView) itemView.findViewById(R.id.waitpay_num);
        }
    }
}
